<?php

class ui_datatable_column extends ui
{
	function __construct($db_name,$name,$sortable,$width,$cell_class=null,$template='')
	{
		global $ti;
		$this->index = null; # this will be set by the datatable
		$this->name = $name;
		$this->db_name  = $db_name;
		$this->sortable = $sortable;
		$this->width    = $width;
		$this->cell_class = $cell_class;
		$this->template   = $template;
		#$ti->log('cell class is: '.$this->cell_class.'');
		
		$this->init(__FILE__,'th',array('class'=>'datatable_column',));
		$this->text($name);
		if($this->sortable)
		{
			$this->set('class','datatable_column_sortable',true);
		}
	}
	
	function get_cell_class()
	{
		global $ti;
		return $this->cell_class;
	}
	
	function pre_render($data=null)
	{
		global $ti;

		$this->set('id',$this->parent->parent->name.'_col_'.$this->index);
		if($this->sortable)
		{
			$this->set('onclick','ti.datatables[\''.$this->parent->parent->name.'\'].sort('.$this->index.');');
		}
		if($this->parent->parent->query->sorts[0] == $this->db_name)
		{
			$this->set('class','datatable_column_sortasc',true);
		}
		if($this->parent->parent->query->sorts[0] == $this->db_name.' desc')
		{
			$this->set('class','datatable_column_sortdesc',true);
		}	
	}
	
	function render_width()
	{
		return '<col width="'.$this->width.'%" />';
	}
}

?>